﻿using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;

namespace ArrayListPractice
{
    class Program
    {
        static void Main(string[] args)
        {
            ForeachHere foreachHere = new ForeachHere();//遍历
            //创建实例
            ArrayList list1 = new ArrayList();
            ArrayList list2 = new ArrayList(list1);
            ArrayList list3 = new ArrayList(20);

            ArrayList list4 = new ArrayList() { 1, 2, 3, 4, 5 };

            //遍历list4
            foreachHere.arrayList = list4;
            foreachHere.PrintForeach();
            Console.WriteLine("------------------------");

            ArrayList list5 = new ArrayList() { "跨越山川河海","跨过丛山峻岭" };

            ArrayList addList = new ArrayList() { 1, 2, 34, 5 };

            for (int i = 0; i < list5.Count; i = i + 1)
            {
                addList.Add(list5[i]);
            }

            foreachHere.arrayList = addList;
            foreachHere.PrintForeach();

            Console.WriteLine("------------------------");
            list5.AddRange(new int[] { 66, 55, 44, 33, 22, 1 });//向集合中添加数组

            foreachHere.arrayList = list5;
            foreachHere.PrintForeach();//遍历list5
            Console.WriteLine("------------------------");

            //插入范围6-7
            ArrayList list6 = new ArrayList() { "aaa", "bbb", "ccc", "dddd","aabb" };
            ArrayList list7 = new ArrayList() { "AaA", "BbB", "ccc", "DdD" };

            list6.InsertRange(2, list7);
            foreachHere.arrayList = list6;
            foreachHere.PrintForeach();
            Console.WriteLine("------------------------");

            //排序
            list6.Sort();
            //Sort 方法将集合中的元素按照字母的 ASCII（<计算机>美国信息交换标准码） 码从小到大排序，相当于字母的顺序。
            foreachHere.PrintForeach();

            Console.WriteLine("------------------------");

            //Sort 方法排序
            ArrayList list8 = new ArrayList() {"g","d","s","a","q"};
            SortHere sortHere = new SortHere();
            list8.Sort(sortHere);

            foreachHere.arrayList = list8;
            foreachHere.PrintForeach();
            Console.WriteLine("------------------------");

        }
    }
}
